package com.qfoud.edu.aunt.commons.login.result;

import com.qfoud.edu.shiro.framwork.annotation.LoginResult;
import com.qfoud.edu.shiro.framwork.result.LoginResultNotify;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author xiaobobo
 * @title: LoginResultNotifyImpl
 * @projectName cd-java-2303-project-parent
 * @description: 登陆成功或者登陆失败的通知
 * @date 2023/5/15  14:18
 */
@LoginResult   //说明这个类的作用是接受登陆的结果
public class LoginResultNotifyImpl extends LoginResultNotify {

    @Override
    public void success(ServletRequest req, ServletResponse response) {
        //TODO :登陆成功了
        System.out.println("登陆成功....");

        HttpServletResponse resp= (HttpServletResponse) response;

        //你想跳转到某一个页面去?
        try {
//            req.getRequestDispatcher("/users/list.action").forward(req,resp);
            resp.sendRedirect("/users/list.action");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void fail(ServletRequest req, ServletResponse resp) {
        //TODO 登陆失败了
        System.out.println("登陆失败.....");
        try {
            req.getRequestDispatcher("/login.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
